class Person {
    private String name;
    private int age=199;
    //类属性  类变量
    public static int count = 99;
    //private int[] elem = new int[10];
    {
        //初始化一些实例数据成员
        //this.name = "gaobo";
        this.age = 999;
        System.out.println("实例代码块");
    }

    static {
        count = 888;
        //this.age = 99999;error
        //初始化静态的数据成员和需要提前准备的一些数据
        System.out.println("静态代码块");
    }
    public Person() {
        System.out.println("不带参数的构造方法！");
    }
    public Person(String name) {
        this.name = name;
    }
    public Person(String name, int age) {
        this.name = name;
        this.age = age;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        this.age = age;
    }

    public void eat() {
        System.out.println(name+" 吃饭！");

        /*{
            //本地代码块
        }*/
    }

    public static void staticFunc() {

    }

    @Override
    public String toString() {
        return "Person{" +
                "name='" + name + '\'' +
                ", age=" + age +
                '}';
    }
}

/**
 * 交换变量的值
 * 如果是简单类型，不能交换，原因是：普通类型是拿不到地址的。
 * 处理的核心思想就是拿到这个变量的地址。
 * 引用类型  new 数字();
 */
class MyValue {
    private int val;

    public int getVal() {
        return val;
    }

    public void setVal(int val) {
        this.val = val;
    }
}


public class TestDemo {

    public static void swap(MyValue myVal1,MyValue myVal2) {
        //int tmp = myVal1.val;
        //myVal1.val = myVal2.val;
        //myVal2.val = tmp;
        int tmp = myVal1.getVal();
        myVal1.setVal(myVal2.getVal()) ;
        myVal2.setVal(tmp);
    }

    public static void main(String[] args) {
        MyValue myValue1 = new MyValue();
        myValue1.setVal(10);
        //myValue1.val = 10;
        MyValue myValue2 = new MyValue();
        myValue2.setVal(20);
        //myValue2.val = 20;

        System.out.println(myValue1.getVal());
        System.out.println(myValue2.getVal());

        swap(myValue1,myValue2);
        System.out.println("=================");

        System.out.println(myValue1.getVal());
        System.out.println(myValue2.getVal());

    }
    /*public static void swap(MyValue myVal1,MyValue myVal2) {
        int tmp = myVal1.val;
        myVal1.val = myVal2.val;
        myVal2.val = tmp;
    }

    public static void main(String[] args) {
        MyValue myValue1 = new MyValue();
        myValue1.val = 10;
        MyValue myValue2 = new MyValue();
        myValue2.val = 20;

        System.out.println(myValue1.val);
        System.out.println(myValue2.val);

        swap(myValue1,myValue2);
        System.out.println("=================");

        System.out.println(myValue1.val);
        System.out.println(myValue2.val);

    }*/



    public static void main11(String[] args) {
        //面向对象
        HomeWork homeWork = new HomeWork();
        homeWork.setNum1(10);
        homeWork.setNum2(20);

        System.out.println(homeWork.add());//30
        System.out.println(homeWork.sub());//-10
        System.out.println(homeWork.mul());//200
        System.out.println(homeWork.dev());//0.5


    }

    public static void main10(String[] args) {
        Person person1 = new Person();
        person1.eat();
        System.out.println(person1.getName());

        //
        new Person().eat();
        System.out.println(new Person().getName());

    }



    public static void main5(String[] args) {
        Person person1 = new Person();
        System.out.println(person1.getAge());

        System.out.println(Person.count);
    }


    public static void main4(String[] args) {
        Person person1 = new Person();
        System.out.println("============");
        Person person2 = new Person();
    }


    public static void main3(String[] args) {
        Person person1 = new Person();
        person1 = new Person();
        person1 = new Person();
        person1 = new Person();
        person1 = new Person();
        person1 = new Person();
        person1 = null;
    }

    public static void main2(String[] args) {
        Person person1 = new Person();
        Person person2 = person1;
    }

    public static void main1(String[] args) {
        Person person1 = new Person();
        System.out.println(person1);
    }


    /*public static void main2(String[] args) {
        Person person1 = new Person();//实例化对象
        System.out.println(person1.name);

        System.out.println(Person.count);

        Person person2 = null;//person2不指向任何对象

        System.out.println(person2.count);

    }
    public static void main1(String[] args) {
        Person person1 = new Person();//实例化对象
        Person person2 = new Person();//实例化对象
    }*/
}